﻿@{
    ViewData["Title"] = "AfterSale";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<style>
    .section {
        display: flex;
        align-items: center;
        margin-bottom: 20px; /* 调整间距 */
    }

        .section label {
            margin-right: 10px; /* 调整标签和输入框之间的间距 */
        }

        .section input[type="number"] {
            width: 60px; /* 调整数字输入框宽度 */
            margin-right: 10px; /* 调整输入框和段落之间的间距 */
        }

        .section p {
            margin: 0; /* 清除段落的默认上下边距 */
        }

    .inline-table td {
        display: inline-block;
        margin-right: 10px; /* 调整列之间的间距 */
    }
</style>

<h1>订房售后设置</h1>
<div class="layui-form">
    <table class="inline-table">
        <tr>
            <td>
                <input type="checkbox" id="orderRoomCheckbox" name="orderRoom" title="支持客户在预订的入住时间(截止当日24点)">
            </td>
            <td style="width:80px">
                <input type="text" id="roomUpto" name="roomUpto" class="layui-input">
            </td>
            <td>
                <label style="margin-left:10px">天前申请退款</label>
            </td>
        </tr>
    </table>
</div>

<div id="radioButtons" style="margin-top: 20px;">
</div>

<h1>售后服务设置</h1>
<div class="section">
    <label for="userSponsor">用户发起退款申请</label>
    <div class="layui-input-inline" style="width: 100px;">
        <input type="number" id="userSponsor" style="width: 100px;" autocomplete="off" class="layui-input" value="7" min="1" max="30" step="1" lay-affix="number">
    </div>
    <p>天后商家未处理，系统将自动同意退款。</p>
</div>
<div class="section">
    <label for="buySponsor">商家同意退货</label>
    <div class="layui-input-inline" style="width: 100px;">
        <input type="number" id="buySponsor" style="width: 100px;" autocomplete="off" class="layui-input" value="7" min="1" max="30" step="1" lay-affix="number">
    </div>
    <p>天后买家未处理，系统将自动拒绝售后。</p>
</div>
<div class="section">
    <label for="orderNumber">买家已退货</label>
    <div class="layui-input-inline" style="width: 100px;">
        <input type="number" id="orderNumber" style="width: 100px;" autocomplete="off" class="layui-input" value="7" min="1" max="30" step="1" lay-affix="number">
    </div>
    <p>天后商家未处理，系统将自动同意退款。</p>
</div>
<div class="layui-btn-container" style="text-align:center">
    <button class="layui-btn layui-btn-primary layui-border-blue" id="saveSettingsBtn">保存设置</button>
</div>
@* <script src="~/aftersale/aftersalesetup.js"></script> *@
<script>
    layui.use(['table', 'form', 'layer', 'laypage', 'jquery'], function () {
        var form = layui.form;
        var layer = layui.layer;
        var $ = layui.jquery;
        var table = layui.table;
        var laypage = layui.laypage;

        $('#saveSettingsBtn').on('click', function () {

            var form = {
                afterSalesSetupId: 1,
                roomUpto: $('#roomUpto').val(),
                roomExpenses: 0,
                serviceCharge: 0,
                userSponsor: $('#userSponsor').val(),
                shopSponsor: $('#shopSponsor').val(),
                buySponsor: $('#buySponsor').val()
            }

            $.ajax({
                url: 'http://localhost:5174/api/AfterSale/UpdateAfterSetUp',
                type: 'post',
                contentType: "application/json",
                headers: {
                    "Authorization": "Bearer " + localStorage.getItem('token')
                },
                data: JSON.stringify(form),
                success: function (res) {
                    if (res > 0) {
                        layer.msg("操作成功")
                    }
                },
                error: function (error) {
                    console.error(error);
                }
            });

            return false; // 阻止表单的默认提交
        });
    });
</script>